<?php

namespace addons\csmitsm\library\xcore\xcore\base;

use think\queue\Job;



abstract class XcAJob
{
    public function fire(Job $job, $data)
    {
        $method = $data['method'];
        $param = $data['param'];
        try {
            $this->$method(...$param);
            trace("This is a queue job");
        } catch (\Exception $e) {
            $this->traceException($e, $this, $method);
        }finally{
            $job->delete();
        }
    }

    protected function traceException($exception, $clsname, $method)
    {
        trace("Queue Job Error: {$clsname}@{$method}:" . $exception->getMessage());
    }

    protected function deleteJob($job)
    {
        if ($job) {
            $job->delete();
        }
    }
}
